import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STColumn, STComponent, STData, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { ChannelSalesService } from '../../services/channel-sales.service';

@Component({
  selector: 'app-parter-article-management-list',
  templateUrl: './list.component.html'
})
export class ParterArticleManagementListComponent implements OnInit {
  schema: SFSchema = {};
  columns!: STColumn[];
  ui!: SFUISchema;
  @ViewChild('st', { static: false })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  spuStatus = '1';
  _$expand = false;

  data = [{ name1: 1111 }];
  constructor(public router: Router, public service: ChannelSalesService, private modalService: NzModalService) {}

  /**
   * 查询参数
   */
  get reqParams() {
    return { ...this.sf?.value };
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this.st.load(1);
  }

  search() {
    // this.st1?.load(1);
  }

  /**
   * 查询字段个数
   */
  get queryFieldCount(): number {
    return Object.keys(this.schema?.properties || {}).length;
  }
  /**
   * 伸缩查询条件
   */
  expandToggle(): void {
    this._$expand = !this._$expand;
    this.sf?.setValue('/_$expand', this._$expand);
  }
  ngOnInit() {
    this.initSF();
    this.initST();
  }

  initSF() {
    this.schema = {
      properties: {
        _$expand: { type: 'boolean', ui: { hidden: true } },
        name: {
          type: 'string',
          title: '文章标题'
        },
        phone: {
          type: 'string',
          title: '分类'
        },
        phone1: {
          type: 'string',
          title: '状态'
        },
        phone2: {
          type: 'string',
          title: '推荐到首页',
          ui: {
            visibleIf: {
              _$expand: (value: boolean) => value
            }
          }
        }
      }
    };
    this.ui = {
      '*': {
        grid: { span: 8, gutter: 4 }
      }
    };
  }

  initST() {
    this.columns = [
      {
        title: '销售渠道姓名',
        index: 'name1'
      },
      {
        title: '手机号',
        index: 'name1'
      },
      {
        title: '所属组织',
        index: 'name1'
      },
      {
        title: '职级',
        index: 'name1'
      },
      {
        title: '等级',
        index: 'name1'
      },
      {
        title: '省市',
        index: 'name1'
      },
      {
        title: '邀请码',
        index: 'name1'
      },
      {
        title: '操作',
        className: 'text-center',
        buttons: [
          {
            text: '修改',
            click: (_record, _modal, _instance) => this.edit(_record)
          },
          {
            text: '禁用',
            click: (_record, _modal, _instance) => this.stop(_record)
          },
          {
            text: '启用',
            click: (_record, _modal, _instance) => this.start(_record.id)
          },
          {
            text: '推荐到首页',
            click: (_record, _modal, _instance) => this.recommend(_record.id)
          }
        ]
      }
    ];
  }
  // 新增
  add() {
    this.router.navigate(['/partner/knowledge/article-management-add'], { queryParams: {} });
  }

  // 编辑
  edit(record: STData) {
    this.router.navigate(['/partner/knowledge/article-management-edit'], { queryParams: {} });
  }

  stop(record: STData) {
    this.modalService.confirm({
      nzTitle: '<i>禁用确认</i>',
      nzContent: `<b>确定禁用此文章吗？</br>`
      // nzOnOk: () =>
      //   this.service.request('', '').subscribe(res => {
      //     if (res) {
      //       this.service.msgSrv.success('冻结成功！');
      //       this.st.reload();
      //     }
      //   })
    });
  }
  start(record: STData) {
    this.modalService.confirm({
      nzTitle: '<i>启用确认</i>',
      nzContent: `<b>确定启用此文章吗？</br>`
      // nzOnOk: () =>
      //   this.service.request('', '').subscribe(res => {
      //     if (res) {
      //       this.service.msgSrv.success('冻结成功！');
      //       this.st.reload();
      //     }
      //   })
    });
  }
  recommend(record: STData) {}
}
